<!DOCTYPE html>
<html>
<head>
<title>GoEasy Test</title>

<script type="text/javascript" src="https://cdn.goeasy.io/goeasy.js"></script>
<script type="text/javascript">
    if(typeof GoEasy !== 'undefined'){
        var goEasy = new GoEasy({
            appkey: 'BC-73a09621d2b24c2cbc33e765c2ee878a',
            userId:"4",
            username:"44",
            onConnected:function(){
                console.log("Connect to GoEasy success.");
            } ,
            onDisconnected:function(){
                console.log("Disconnect to GoEasy server.");
            } ,
            onConnectFailed:function(error){
                console.log("Connect to GoEasy failed, error code: "+ error.code+" Error message: "+ error.content);
            }
        });
    }

    subscribe();
    function subscribe(){
             goEasy.subscribe({
                channel: 'notification',
                onMessage: function(message){
                    console.log('Meessage received:'+message.content);
                },
                onSuccess:function(){
                    alert("成功连接11111111111GoEasy。");

                    console.log("Subscribe the Channel successfully.");

                },

                onFailed: function(error){

                    console.log("Subscribe the Channel failed, error code: "+ error.code + " error message: "+ error.content);

                }

            });

    }

     function publishMessage(){
          goEasy.publish({
                channel: 'notification',
                message: 'You received a new notification222',
                onSuccess:function(){
                    alert("发布成功2222,GoEasy。");
                    console.log("Publish message success444.");

                },
                onFailed: function(error){
                    alert("发布失败4444,GoEasy。");
                    console.log("Publish message failed, error code: "+ error.code +" Error message: "+ error.content);

                }
            });

     }

     function unsubscribe(){
                goEasy.unsubscribe({
                    channel:"notification",
                    onSuccess: function(){
                        alert("取消订阅3333,GoEasy。");
                        console.log("Cancel Subscription successfully.");

                    },
                    onFailed: function(error){

                        console.log("Cancel the subscrition failed, error code: "+ error.code + "error message: "+ error.content);
                    }

                });
            }

 </script>
</head>
<body>
  <input type="button" value="publish" onclick="publishMessage()"/>
  <input type="button" value="unsubscribe" onclick="unsubscribe()"/>
  <input type="button" value="subscribe" onclick="subscribe()"/>
</body>
</html>